package com.xh.demo.controller;

import com.xh.demo.model.table.User;
import com.xh.demo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;

@Slf4j
@RestController
//@Api(tags = "用户相关-接口")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/master/user")
//    @ApiOperation(value = "保持用户信息-master", notes = "555:系统未知异常")
    public User saveByUserMaster(@RequestBody User user) {
        User lakeUser = userService.saveByUserMaster(user);
        log.info(lakeUser.toString());
        return lakeUser;
    }

    @PostMapping("/other/user")
//    @ApiOperation(value = "保持用户信息-other", notes = "555:系统未知异常")
    public User saveByUserOther(@RequestBody User user) {
        User lakeUser = userService.saveByUserOther(user);
        log.info(lakeUser.toString());
        return lakeUser;
    }

    @PostMapping("/master/user/ext")
//    @ApiOperation(value = "保持用户信息-master", notes = "555:系统未知异常")
    public User saveByUserMasterTransactional(@RequestBody User user) {
        User lakeUser = userService.saveByUserMasterTransactional(user);
        log.info(lakeUser.toString());
        return lakeUser;
    }

    @PostMapping("/other/user/ext")
//    @ApiOperation(value = "保持用户信息-other", notes = "555:系统未知异常")
    public User saveByUserOtherTransactional(@RequestBody User user) {
        User lakeUser = userService.saveByUserOtherTransactional(user);
        log.info(lakeUser.toString());
        return lakeUser;
    }

    @GetMapping("/master/user/{id}")
//    @ApiOperation(value = "查询用户信息-master", notes = "555:系统未知异常")
    public User getUserByMaster(@PathVariable("id") Long id) {
        User lakeUser = userService.getUserByMaster(id);
        return lakeUser;
    }

    //    @ApiOperation(value = "查询用户信息-other", notes = "555:系统未知异常")
    @GetMapping("/other/user/{id}")
    public User getUserByOther(@PathVariable("id") Long id) {
        User lakeUser = userService.getUserByOther(id);
        return lakeUser;
    }


}